<template>
  <div>
    <div>
      <div class="newshead">
        <div class="title-head" title="消息通知">消息通知</div>
      </div>
    </div>
    <div>
      <van-tabs @click="onClick">
        <van-tab title="热点新闻">
          <div class="area">
            <van-list v-model="loading" :finished="finished">
              <van-cell @click="newsdeatil(item)" icon="location-o" v-for="(item,index) in newsList" :key="index"
                :title="item.title" />
            </van-list>
          </div>
          <van-pagination @change='nextpage' v-model="currentPage" :total-items="total" :show-page-size="5"
            force-ellipses />
        </van-tab>
        <van-tab title="公司公告">
          <div class="area">
            <van-list v-model="loading" :finished="finished">
              <van-cell @click="noticedeatil(item)" icon="location-o" v-for="(item,index) in noticeList" :key="index"
                :title="item.title" />
            </van-list>
          </div>
          <van-pagination @change='nextpage' v-model="currentPage" :total-items="total2" :show-page-size="5"
            force-ellipses />
        </van-tab>
      </van-tabs>
    </div>
    <div class="footer">
      <div class="aboutme">
      </div>
      <van-divider />
      <div class="last">
        <a href="http://www.beian.miit.gov.cn">
          备案号：苏ICP备20041612号
        </a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PhoneNews',
  data () {
    return {
      loading: false,
      finished: true,
      noticeList: [],
      newsList: [],
      currentPage: 1,
      total: 0,
      total2: 0
    }
  },
  methods: {
    onClick (name, title) {
      this.$toast(title)
    },
    getNews () {
      this.$axios({
        method: 'get',
        url: '/news/select?page=1&pageSize=10'
      }).then((res) => {
        if (res.status === 200) {
          this.newsList = res.data.data.rows
          this.total = res.data.data.records
        }
      })
    },
    getNotice () {
      this.$axios({
        method: 'get',
        url: '/notice/select?page=1&pageSize=10'
      }).then((res) => {
        if (res.status === 200) {
          this.noticeList = res.data.data.rows
          this.total2 = res.data.data.records
        }
      })
    },
    nextpage (e) {
      this.$axios({
        method: 'get',
        url: '/news/select?page=' + e + '&pageSize=10'
      }).then((res) => {
        if (res.status === 200) {
          this.newsList = res.data.data.rows
          this.total = res.data.data.records
        }
      })
    },
    nextpage2 (e) {
      this.$axios({
        method: 'get',
        url: '/notice/select?page=' + e + '&pageSize=10'
      }).then((res) => {
        if (res.status === 200) {
          this.noticeList = res.data.data.rows
          this.total2 = res.data.data.records
        }
      })
    },
    newsdeatil (item) {
      this.$router.push({
        path: '/PhoneDeatil',
        query: {
          name: 'News',
          id: item.id
        }
      })
    },
    noticedeatil (item) {
      this.$router.push({
        path: '/PhoneDeatil',
        query: {
          name: 'Notice',
          id: item.id
        }
      })
    }
  },
  mounted () {
    this.getNotice()
    this.getNews()
  }
}
</script>

<style scoped>
.newshead {
  width: 300px;
  height: 60px;
  background: rgb(15, 66, 155);
  color: white;
  font-size: 25px;
  text-align: center;
  overflow: hidden;
  margin: 15px auto;
  border-radius: 5px;
}
.title-head {
  line-height: 40px;
  margin: 10px 0;
  cursor: pointer;
}
.area {
  min-height: 510px;
}
.footer {
  text-align: center;
  background: #364a62;
  margin-bottom: 60px;
  overflow: hidden;
  margin-top: 15px;
}
.aboutme {
  margin-top: 10px;
  color: white;
  font-weight: 600;
}
.content {
  margin-top: 10px;
  text-align: center;
  font-weight: normal;
}
.last {
  height: 20px;
  line-height: 20px;
  color: white;
  margin-bottom: 16px;
}
a {
  text-decoration: none;
  color: white;
}
</style>
